package cn.lyh.qinfeng.plugin;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import cn.lyh.qinfeng.service.KaiTuanSerive;
import net.lz1998.cq.event.message.CQGroupMessageEvent;
import net.lz1998.cq.robot.CQPlugin;
import net.lz1998.cq.robot.CoolQ;

/**
 * @author lyh
 * @version 1.0
 * @date 2020/3/20
 * @Description
 */
@Component
public class GetTuanInfoPlugin extends CQPlugin {
    @Autowired
    KaiTuanSerive kaiTuanSerive;

    @Override
    public int onGroupMessage(CoolQ cq, CQGroupMessageEvent event) {
        // 获取群查询团队信息 查看团队
        String groupMsg = event.getMessage().trim();
        System.out.println("groupMsg = " + groupMsg);
        Integer gourpId = Math.toIntExact(event.getGroupId());
        String result = "";
        if ("查看团队".equals(groupMsg)) {
            if (kaiTuanSerive.getTuanInfo() != null) {
                result += kaiTuanSerive.getTuanInfo().toString();
            }
            else {
                result += "暂时没有团队信息";
            }
            cq.sendGroupMsg(gourpId, result, false);
            return MESSAGE_BLOCK;
        }
        return MESSAGE_IGNORE;
    }
}
